//
//  LoginViewController.m
//  WhatsChat
//
//  Created by 彭琦峰 on 16/3/22.
//  Copyright © 2016年 tanchen. All rights reserved.
//

#import "LoginViewController.h"
#import <AVOSCloud/AVOSCloud.h>
#import "RegistViewController.h"
#import "AppDelegate.h"
#import "TabBarController.h"

@interface LoginViewController ()

@property (nonatomic,strong)AppDelegate *appdelegate;


@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
  
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.userNameTextField resignFirstResponder];
    [self.passwordTextField resignFirstResponder];
}
- (void)viewWillAppear:(BOOL)animated{

    //接收值
    self.userNameTextField.text = [[NSUserDefaults standardUserDefaults]objectForKey:@"userName"];
    
}

//忘记密码
- (IBAction)cancleAction:(UIButton *)sender {
}
//登录
- (IBAction)loginAction:(UIButton *)sender {
    
    [AVUser logInWithUsernameInBackground:self.userNameTextField.text password:self.passwordTextField.text block:^(AVUser *user, NSError *error) {
        if (user != nil) {
            //获取appdelegate中的属性
            self.appdelegate = [UIApplication sharedApplication].delegate;
            TabBarController *tabBarVC = [[TabBarController alloc]init];
            self.appdelegate.window.rootViewController = tabBarVC;
            tabBarVC.selectedIndex = 0;
            
        } else {
            
        }
    }];
}
//注册
- (IBAction)registAction:(UIButton *)sender {
    
    RegistViewController *registVC = [[RegistViewController alloc]init];
    //模态效果
//    registVC.modalTransitionStyle = UIModalTransitionStylePartialCurl;
  
    [self presentViewController:registVC animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
